﻿#region Copyright Info

// 
// Majesty of Omega - The next evolution of macro management space strategy
// 
// Copyright 2007-2009 André Claaßen
// 
// This file is protected by the terms and conditions of the
// Microsoft Community License (Ms-CL 1.1), a copy of which should
// have been distributed along with this software. If not,
// you may find the license information at the following URL:
// 
// http://www.microsoft.com/resources/sharedsource/licensingbasics/communitylicense.mspx

#endregion

#region

using System.Collections.Generic;
using Majesty_of_Omega.Logic.GameConfiguration;
using Majesty_of_Omega.Model.Space;
using Majesty_of_Omega.Model.Game;
using Majesty_of_Omega.Logic.Generator;
#if NUNIT
using NUnit.Framework;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
using ClassInitialize = NUnit.Framework.TestFixtureSetUpAttribute;
using ClassCleanup = NUnit.Framework.TestFixtureTearDownAttribute;
#elif MBUNIT
using MbUnit.Framework;
using TestClass = MbUnit.Framework.TestFixtureAttribute;
using TestMethod = MbUnit.Framework.TestAttribute;
using TestInitialize = MbUnit.Framework.SetUpAttribute;
using TestCleanup = MbUnit.Framework.TearDownAttribute;
using ClassInitialize = MbUnit.Framework.TestFixtureSetUpAttribute;
using ClassCleanup = MbUnit.Framework.TestFixtureTearDownAttribute;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
#endif


#endregion

namespace Test.Majesty_of_Omega
{
    /// <summary>
    ///This is a test class for TestStartPositionSearcher and is intended
    ///to contain all TestStartPositionSearcher Unit Tests
    ///</summary>
    [TestClass]
    public class TestStartPositionSearcher
    {
        /// <summary>
        ///A test for CalcMinimumDistanceInJumps
        ///</summary>
        /// <remarks>
        /// <code>
        ///                  Star 1        o
        ///                               / \
        ///                              /   \
        ///                  Star 2     o     |
        ///                              \   /  
        ///                               \ /       Star 4
        ///                  Star 3        o---------o--------o Star 5
        ///              
        ///                  Star 6   o (not connected)
        /// </code>
        /// </remarks>
        [TestMethod]
        public void TestCalcMinimumDistanceInJumpsInConstructedGalaxy()
        {
            // 1. Create test galaxy
            StarGalaxy galaxy = new StarGalaxy();
            Star star1 = galaxy.AddStar(new Star("Star 1"));
            Star star2 = galaxy.AddStar(new Star("Star 2"));
            Star star3 = galaxy.AddStar(new Star("Star 3"));
            Star star4 = galaxy.AddStar(new Star("Star 4"));
            Star star5 = galaxy.AddStar(new Star("Star 5"));
            Star star6 = galaxy.AddStar(new Star("Star 6"));

            galaxy.AddStarLane(star1, star2);
            galaxy.AddStarLane(star2, star3);
            galaxy.AddStarLane(star1, star3);
            galaxy.AddStarLane(star3, star4);
            galaxy.AddStarLane(star4, star5);

            AssertCalcDistance(star1, star1, 0, "There is no distance between the same star");
            AssertCalcDistance(star1, star2, 1, "minimum distance between star 1 and star 2 is 1");
            AssertCalcDistance(star1, star3, 1, "minimum distance between star 1 and star 3 is 1 (see picture)");
            AssertCalcDistance(star1, star5, 3, "minimum distance between star 1 and star 5 is 3 (see picture)");
            AssertCalcDistance(star1, star6, int.MaxValue, "infinetly distance, because star 6 is not connected");
        }

        /// <summary>
        /// Asserts the calculated distance between the too stars.
        /// </summary>
        /// <param name="star1">The star1.</param>
        /// <param name="star2">The star2.</param>
        /// <param name="expectedDistance">The expected distance between the stars.</param>
        /// <param name="message">The message for the assertion.</param>
        private static void AssertCalcDistance(Star star1, Star star2, int expectedDistance, string message)
        {
            int actualDistance = StartPositionSearcher.CalcMinimumDistanceInJumps(null, star1, star2);
            Assert.AreEqual(expectedDistance, actualDistance, message);
        }


        /// <summary>
        /// Tests the StartPositionSearcher with a normal game setup with players.
        /// </summary>
        [TestMethod]
        public void TestNormalGameSetupWithPlayers()
        {
            SaveGame newGame = TestDataGenerator.TestSaveGame;
            StartPositionSearcher positionSearcher = new StartPositionSearcher(newGame);
            List<StartPositionSearcher.StartPosition> positions = positionSearcher.GenerateStartPositions();
            Assert.AreEqual(newGame.NumberOfPlayers, positions.Count);
        }
    }
}